package main

import (
	"Doge/config"
	db2 "Doge/config/db"
	"Doge/models"
	"flag"
	"fmt"
	"os"
)

var (
	confFile string
)

func initArgs() {
	var (
		currentDir string
		path       string
	)

	currentDir, _ = os.Getwd()
	path = currentDir + "/config/config.json"
	flag.StringVar(&confFile, "config", path, "指定config.json文件")
	flag.Parse()

}

func main() {
	var (
		db  *db2.DB
		err error
	)


	//初始化命令行参数
	initArgs()

	//加载配置
	if err = config.InitConfig(confFile); err != nil {
		fmt.Println("加载配置文件错误", err)
		panic(err)
	}

	if db, err = db2.NewDB(); err != nil {
		fmt.Println("连接数据库报错:", err)
		panic(err)
	}


	if err = db.Db.Set("gorm:table_options", "ENGINE=InnoDB").AutoMigrate(&models.Delayed{}); err != nil {
		fmt.Println("migrate错误:", err)
		panic(err)
	}

	fmt.Println("migrate完成")




}
